#ifndef _MAP_H_
#define _MAP_H_

#include <list>
#include <vector>
#include <fastsig/fastsig.hpp>
#include "mapformat.pb.h"
#include <string>

class Entity;
class Layer;
class AnimatedSprite;

class Map:boost::noncopyable
{
friend class Renderer;
public:
	Map();
	~Map();
	bool loadFromFile(const SQChar* path);
	void saveToFile(const SQChar* path);
	void addEntity(Entity* entity);
	void removeEntity(Entity* entity);
	void addAnimatedSprite(AnimatedSprite* anim);//TODO: improve design
	void onEnter();
	void onLeave();
	void update();	
	void addLayer(const SQChar* name);
	void reload();
	Layer* getLayerByName(const SQChar* name);
	Layer* getLayerByIndex(unsigned int index);
	Entity* getEntityAt(const sf::Vector2f& position) const;
	static Map* defaultMap;//default map for newly created entity
private:
	//static Map voidMap;//any entities in this map will be destroyed at the end of the game
	fastsig::signal<void()> updateSignal;
	fastsig::signal<void()> animateSignal;
	std::list<Entity*> entities;	
	std::vector<Layer*> layers;
	std::wstring name;
};

void objToTable(SquirrelObject& table,const mapformat::Object& obj);
void tableToObj(SquirrelObject& table,mapformat::Object& obj);

#endif